refactor getPreferredLocation.