Revised and improved code for the upper resolve layer.