Added some more logging and removed the buggy replace_... function.