Big refactoring due to MySQL feature.