Tidying up the code