use memoryviews to avoid a little bit of copypasting while also not losing an order of magnitude of speed