Refactor python version detection