docstrings and simplified matrix filter function