shoudln't ``$previous`` be updated in the loop too ?