better errors

Improve error logic