Changes in the setHeadDirection function