Changing the initialization so it would search also from the end