templateize the main function
various