removed many global variables. cross platform time functions