improve error messages and simplify tail