Bug Fixes

Many small bug fixes.