fix level resolve algorithm