add directions and line detect function