Unstable setResourceMap algorithm (incorrect result)