Various fixes for issues #19 and #31