Bug fix for incorrect level checking code