MySQL refactor bug fix