Added checkDirection function.