Refactoring to cleaner code