ported changes by Fabio #15 into develop branch