Final

Refactoring and final testing