add timer and refactor