Refactoring and added protection against bad priority values.