refactoring second pass