more mysql cleanup + code cleanup