translating this to python, putting some debugging statements