fixed for compatability for python 2 and 3
fixed 2/3 compatability and reorginized