Make this work with Python 3, and do some minor cleanup