I've integrated your changes and made a couple of fixes of my own.