change remove functions to free the data memory together with the element