Reordered  some code and fixed assert not executing when switching world