Bunch of small bug fixes