Fixing bug in db insert