Refactored error report functions to a library and added doc blocks