rearranged python code