Fixing bug with replace