This is original algorithm from aaA.d