Fix option handling and add better tests for it.