need to tidy up but the basics are there