solved infinite loop bug