refactoring and adding priority