Adding location handling.

Also implemented some source refactoring.