improved origin handling