Minor fixes on documentation and slight logic unrolling