This is a pretty insane commit, but hey, is a pretty big rewrite