Fixed setDirection function