Improved time machine and added unit test for it.