Filled out more helper functions and general tidying up