tweaking direction algorithm