fixed issues and added unittests for timetools