Add priority field
Move integer parameters out
Add sorting by priority, and fix max_threads check