added code for graceful degradation and tests