Adding doc blocks and fixing bugs