add error handling more places.