fix issue #9, #10 and #12