Ported to Python 2.7 and pep8ed a little