Fix build and some bugs for basic functionality.