Refactor version negotiation.

#201