rough almost fully working version