risk algorithm
some cleanup