more comments explaining strange algorithm