Edit topology code for clarity, add reference hash function