bug fix, ported ruby to python