Fixed: #638, #640, and misc cleanup fixes