bug fix on database insert