Optimizing for memory and cleaning up.