reorganized and updated with respect to latest layer changes