bug fixes and reorganization of libs