Make version detection more robust