improve dialog code