added Johann's fixes from SF SVN