Here is the updated code, in case anyone is interested. The one on the Discussion is outdated.