mysql refactoring