added graceful error handling