new class structure and fix infinite loop