Add documentation to server. Break up large functions along the way.