Greatly improved findLevelIndex, various reorganizations/refactors