fixed dictionary loop bug