Added priority feature and bug fix

Added priority feature and several bug fixes.