added while loop to wacky code