fixed many bugs, now this version (lib + tests) compiles