first working version with bug