file write working
tidy up
small fixes