Refactor time logic in the server