Improving Memory for Optimizatioin and Learning in Dynamic Environments