Initial commit.
Copied from original.
Updated to work on toolserver.
Cleaned up and add comments.