initial mostly working version