Added matrix handling