Improve overriding of options

This commit further improves the overriding of options in several ways:

- Guarantees that we check for sealed and overrides in the correct order
- An option can always override itself (this should be a rare corner
  case)
- Merging logic separated from overriding logic
- Further test cases