Code fixed to operate correctly.