First working version of priority handling