step by step with refactoring to patterns