Tweaked to (mostly) comply with PEP 8 style guidelines.