Integrate new version of Joel's code