Refactor code in preparation to timeevent support