fixed replace chunk function (infinite loops was possible by a chunk
refering to himself)