Move stuff from models to helpers module in core
Remove remaining prints
Refactor and centralize topology queries
Move code to path helpers
Rework overlapping code
Fix overlapping comparison (fixes #710)