Misc small bug fixes