Optimize ram usage