code clean up. latest changes from sphinx trunk
upgrade from svn trunk