Refactor entire code