reorganized, and included some other minor patches that might be useful