Week 5 refactoring (not finished)