moved some code from my google code SVN repository