remove unnecessary buffer copies
precalculate indices