reordering code in controller