use std::size_t consistently and avoid possible loss of data