refactoring to testable design