Fixes for issues 2, 3, 4 and 5

Pull request fixes mentioned issues.

If desired, I can split them into separate pull requests.