optimize memory consumption