incorporate fmonnier's latest changes, and add a few of mine