Revised to work under python 3.3