switched to using flat arrays