Reorder some code to improve the semantic split between two functions