many fixes, working version