Fixed replacement bug