Edited preMat function