refactoring code for legibility