starting big MySQL refactoring (do not check out this code, it is very buggy)