Added a check that prevents possible garbage value.

This fixes a fairly unlikely to occur, but likely to be fatal garbage value.