Clone of Peter-Crumb's implementation