Refactor version handling into a with statement