Refactoring the entire code