a few fixes and improve error messages