cleaning up deeply nested structure