Fixed code to work for reservoir sampling