double loop not working