fixes issues #11, #16, #10 and #6