various fixes. Working prototype