managing memory as much as possible