Bugfix from Pablo, changes from Alessio