Tidying up of code