almost done working version