Refactoring

Complete refactoring with a new API