Refactoring

Introducing Interfaces and adding unit tests.