Refactoring code for legibility