Clock related fixes, fixes some valgrind errors