Duplicated code. Better use ang and direction variable, change them in every loop iteration.