Tidying up code to make it easier to work with