Solved memory issue and optimized M_build