Created _priority_calc function; cythonised it and ssd function