Fix #1586 and add tests for more coverage
Merge pull request #1587 from visionmedia/fix-issue-1586

Fix #1586 and add tests for more coverage