Modify the code to be a bit more pythonic

This fixes #1