Reorder some code blocks for better readability.