added functional realloc that follows rules (uses memcpy but so does zahran's)