Updated code to run under Python 3.4.1