fixing reference
tidying up code