I broke it again. Gonna do a complete rewrite.
WIP