Fix the timer + some refactoring