Split this version logic out and write some unit tests for it, it's confusing.