Fixed bugs with "mysql has gone away"