back func and optimize code