refactor code , complete copy paste del function