fixing some error handling.