add demo and optimize code