bug fix / improvement contributed by f2brossi@gmail.com