direction calculation added