Refractoring, documentation and improved error handling.