Huge rewrite, still WIP