Some refactoring and fixing/clarifying of the intersection code.