Complete refactoring.

- new API
- refactor all modules
- add tests