Adjusted reading and replacement code so it now works and replaces things properly