edits to speed up and reduce memory usage