adding trent's original code from svn