Move mysql sync into seperate function.