more tidying
added error checking
fixed some obviouis errors
Finalisation