cleaned up code for geometry logic