Small code reorg and more doc