Fixed a rather silly bug. Now works, but still isn't pretty.