error fixes and tidy up