fixing Michael's code