Bug fix & tested in python2