changed error handling and exiting a bit