Many small bug fixes