Fixing numerous bugs introduced by myself and swarley.