improve documentation and add error type