Fixing bugs in convert database script