refactored; add doc blocks