Fix for out of ranges error