you are still returning some default value here, that I think we should not. Just return an error when resourceToWeightMap is empty (the correct place for initialization is what you are doing in line 110).