small bug fixes
many bug fixes and style changes