refactoring for reducing lines of code