Reimplement loop and properly handle errors and display

Reviewed-by: Philippe Godin <pgodin@iweb.com>