Fix bugs in ResourceManager