merge w Antonino's code and fix errors