Numerous style and small bug fixes.