Extracts the setup and loop stages into methods.