changed som if's to some while's