[FIX] small bugs in the find/replace algorithm, standardize indentation