Update from Porcelli's code