updated matchLevel function