geometry cleanup and optimization