Add cache and improve query-replace-regexp messages.
Clean up comments & docstrings