fix bug with level detection