various little fixes (one was critical though)
better use of str_replace
remove dead assignments