The code taken from developerforce.com plus a new test class for coverage.