added option to set thread priority