Reduce nesting and remove extra whitespace in python_helper