gain refactor