build better location function