Moved docstrings to proper position
Split functions into sensible namespaces