Refactor to make the code a bit nicer and remove redundant or broken things