changed coding style from vars to named functions
extracted clock into a service