rewrite direction calculations