cleanup and update memory computation