The mesh creation method is currently too long and complex. It must be refactored into smaller methods and tested.