option parsing fixes

fixes for  #70, #350, and #1084

starts with an old commit from @gvalkov, then more commits and tests from me.

(using some old PR's from @hltbra to navigate thru this;  probably one more PR coming after this with some logging fixes)