Complete rewrite. It actually works though, so it's cool