Code cleanup and moves time messure to own module