Added matrix accumulation function