enhanced code to support proper python version