mostly working
Final working version