Refactor + make python version detection works with version < 2.7