Refactor and thoroughly test time model