pkg builds. Added tests. Fixed some bugs.