Fixed while loop in custom_reverse