Updated with templating to support passing a variable type argument to the thread