Moar refactor. Moving common code into endpoint.