first version of working code