merge with Eugenio's code