implementing sweep except for handling ties