added function to save memory usage