Working dynamic XP algorithm

Need to comment everything still, but other than that I'm pretty proud
of it.
Bit of tidying up