lots of small bug fixes tweaks