refactoring js, integrating timer and matcher