Fix a few bugs in initial version of main lib

It seems to be functional now