Added a lot of improvements mentioned in pull request #1.