Fixed last connection undefined problem