Python: Code cleanup