Fix #49: fix level calculation