attempt on fixing endless loops