added Timer class
some other fixes and refactorings