Spliced the main function up.