Hacked together this piece of junk so it actually works. I'm not proud of this...