cleaned up and commented - more to do