small bug fixes and cleanup