Implemented protocol + tests
Minor refactorings