working, code needs tidy up