updated version (by Andrea)