Corrected a longstanding bug and cleaned up some slightly misleading code.