about to start tidying up the code