Fix issues #1, #6, #9 and #11