Changed to use generator