Slight tidyup up, and documenting functions