added exceptions for uses of recover_memory not meeting nesting requirements plus tests