Refactoring towards to more testability

Ref