Changed error handling a bit