first mostly working version