tweaking this alg, getting bad results with the abs for some reason...