General cleanup and small bug fixes.