final updated working version