Refactored the location graph code to be more structured