Merged #3 and #4.

@gguuss please review this pull request. This merges your updates with my recent commit.