first working version of code