Fix #276
Fix  #275
fix #277
Fix #278
Fix #295. Small tweak for #275 and #278.