Reworked error handling and improved documentation