Split into more functions to ease reading