homework6: refactoring