Add doc blocks and improve formatting