Step by step tutorial refactoring hardly testable code