size_t changed to int to avoid comparison of different signs