Tidying up some code