Fix issues #1, #2, and #26 

This pull request is the same as #13 except commit b5d4aad has been replaced by 4978024 with new commit message.