Added doc blocks, refactored stuff