Moved tri and trip header handling out of main method to remove code clutter