including @esmail's changes from a previous PR #29