refactoring and incorporating boilerpipe