Refactoring code to be more readable