#2 code from SVN lib