add doc blocks, simpler code