added reduce and matrix functions