fix race condition and boundary checking in collection data file