Further improve mgdb script.