fixing some error handling