fix for replacewith bug