Decrease the use of the IO monad in the do-block of the main function.
Move some processing from the main function to helper functions.