working version of Henry’s code