refine code structure and add gain function, gain function is unfinished
refine code structure and add gain function, gain function is unfinished