Split out Python code a bit

Thoughts?