core: improved main class detection