error handling

improved error handling in buildAnalytics