improve error management to pass test more properly