working code - but not yet pretty