Totally rewrote everything.

Now it actually works :)