Docstrings and conditions for sorting functions