gave all important and slightly non-self-evident functions a docstring