updated to stop infinite loop