modification to reduce memory usage