Fixed index error on option parsing.

Also merges in master. There was a merge conflict on `CMakeLists.txt`, so pay attention to that addition. I'm not sure if it needs to be there or not. 
All this text was the result of a merge conflict, and I guessed about whether it should be there or not. I just accepted the whole chunk. @DavidRagazzi Please review and make sure this should all be here.