Improved handling of nested resources; misc fixes and improvements