refactoring to reduce lines of code