added doc blocks; cleaned code