in-place replace bugfix from untd & debugging cleanup