public static Chunk[] overlay( Match match, Chunk[] chunks )
	{
		int begin = 0;
		int matchStart = match.offset;
		int matchEnd = match.offset+match.length;
		ArrayList<Chunk> newChunks = new ArrayList<Chunk>();
		for ( int i=0;i<chunks.length;i++ )
		{
			Chunk current = chunks[i];
			// 1. current overlaps match on the left
			if ( matchStart < begin+current.getLength() 
				&& matchStart > begin )
			{
				Chunk[] parts = current.split( matchStart-begin );
				newChunks.add( parts[0] );
				begin += parts[0].getLength();
				current = parts[1];
			}
			// 2. current overlaps match on the right
			if ( matchEnd < begin+current.getLength()
				&& matchEnd > begin )
			{
				Chunk[] parts = current.split( matchEnd-begin );
				parts[0].addState( match.state );
				newChunks.add( parts[0] );
				begin += parts[0].getLength();
				current = parts[1];
			}
			// 3. match completely overlaps current 
			if ( matchStart <= begin && matchEnd 
				>= begin+current.getLength() )
			{
				current.addState( match.state );
				current.version = match.getVersion();
				begin += current.getLength();
				newChunks.add( current );
			}
			// 4. match doesn't overlap current at all
			else /*if ( matchEnd <= begin || matchStart 
				> begin+current.getLength() )*/
			{
				newChunks.add( current );
				begin += current.getLength();
			}
		}
		Chunk[] array = new Chunk[newChunks.size()];
		return newChunks.toArray( array );
	}