functions saves variables in the middle to save on memory