Make gain function private. Added test.