Refactored code. Removed clock_gettime method because it is invalid in c99.