Complete protoype - small bugfixes

This version passes make check.