BUG

I just ran a quick test and everything was A OK. Seems like I'm going to have to do a bit of a rewrite
EDIT: After further debugging, I think it was down to using variables that conflicted with the Wordpress core. So just for anyone in the same situation, make sure you're using unique variables!!