option parsing fixes

fixes for  #70, #350, #1084, and #1195

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)