Fixed bug with priority comparison and added unit tests to prevent reoccuring.