added accuracy test, refactor to 2d array instead of flattened matrix