bug fixes and reorganization