Fixes for #169, #164, #162 and #114