small bug fixes and elimination of dead code