revised for correctness