Got geometry working reasonably well.

Reorganized the code a little.