Python - Rewriting and restructuring.