Added protection against empty histos

Supersedes #134