Refactoring codes to make priority more clear