Made tons of refactoring.

Also added unix and win32 of time_subsystem and it's low level APIs.