MySQL state: several refactor bugs