Adding tests for timeutil and some refactoring