refactoring code for more maintainability