numerous small bug fixes