refactoring code in a more unobtrusive way