moved ugly code that will be replaced to misc.h; some timer stuff