This should solve all the issues reported in this pull request and the ones covered during code review. Additionally this closes #156, closes #154, closes #35, and closes #22.