correct residency calculation