improve dialog function