Documented some functions, and improved the logging