adding database transaction to fix record insertion issue