Reordered and formatted code