refactoring code for easier readability