Optimize the resize code and also deleteduplicate inecesary code.