This code repeats, move it to a separate function above and call it when needed.