using buffer and index