Major refactoring

- Rewrote most of the stack
- Fixes #156