Put each step into a separate function