First cut of working code