Fix bug in replaceShape method