Refactor logic around level_table