fix last insert id and add catch exceptions