some modification to work on python 2.4