Tidied up the codebase, fixed some todos