Tweaks to Ed's code