Refactor Python