Add some documentation. Break some code out to its own function.