Improved error logic and status messages.