General refactor & cleanup

This was just a reordering of the logic just to avoid nested if statements & a general refactor of the code.

It's probably worth taking a look through this one as it's quite opinionated, it'd just be good to get another developers take on my coding style.

Thanks Tom!