Rebuilt in Python, including a bunch of error handling etc.