Reorder logic for better readability.