refactor and add timer