Refactor neighbourIndices

Sorry, I couldn't resist having a go at rewriting this shockingly repetitive bit of code...