refactored checkAnswer code