Extracted main method.