Add doc generator and tweak code a bit