Initial rewrite implementation

Still have to add all those error handlers and test it without all the
hacks