Break a big function in two to improve readability