fix more than 2 replacements on line bug

fixes #9 - also some optimizations