Move main code into a method.