Initial version refactored from geometry