refactor; correctness