rework #1

Add some interfaces to get testability and flexibility.