add helpers for level_t, fix some bugs