Clean up python code a bit