Separate big while loop into many
Separate extraction functions