code: function() {
  				var segList = svgedit.path.path.elem.pathSegList;
  				var len = segList.numberOfItems;
  				
  				var remItems = function(pos, count) {
  					while (count--) {
  						segList.removeItem(pos);
  					}
  				};
  
  				if (len <= 1) {return true;}
  				
  				while (len--) {
  					var item = segList.getItem(len);
  					if (item.pathSegType === 1) {
  						var prev = segList.getItem(len-1);
  						var nprev = segList.getItem(len-2);
  						if (prev.pathSegType === 2) {
  							remItems(len-1, 2);
  							cleanup();
  							break;
  						} else if (nprev.pathSegType === 2) {
  							remItems(len-2, 3);
  							cleanup();
  							break;
  						}
  
  					} else if (item.pathSegType === 2) {
  						if (len > 0) {
  							var prev_type = segList.getItem(len-1).pathSegType;
  							// Path has M M
  							if (prev_type === 2) {
  								remItems(len-1, 1);
  								cleanup();
  								break;
  							// Entire path ends with Z M 
  							} else if (prev_type === 1 && segList.numberOfItems-1 === len) {
  								remItems(len, 1);
  								cleanup();
  								break;
  							}
  						}
  					}
  				}	
  				return false;
  			}
docs: Cleanup