Added matrix tests and improvements