Refactor variable definition order