Refactor gateway options to its own class.

Fixes #5613