fixed issues in find replace functions and added comments