Debug algorithm function. Works apart from negative runs