changed let structure for error handling