integrated patricks latest updates, consistent to svn r369. example files will be merged next