Tidy up back-end code

...rrors. Basically changed everything, I'm a boss.