Refactore and fix time