working except for loop