working version
tidy up