Reordered a few lines to improve the flow