Merging mex's changes into the main branch