Some cleanup and fixes