Various small bug fixes