some fixes to ResourceManager, set code order