updated to use matrix methods