matrix algorithm added