Refactoring

I've refactored the code, and added some new classes and interfaces