Made console error handling more robust.