clean up python code a bit