Fix the memory usage and const declarations