Simplified the contour relations code a bit and made it more readable.