Refactor to improve readability

This tidies up the code a bit to remove unneeded things and tries to improve
the readability a bit.