Refactoring of geometry functions and initial tests for geometry.