Major refactoring, API change

- Rewrote most of the stack
- Fixes #126
- Fixes #156