Refactor js code for Quizzes