week12 refactored