Refactoring code in world.cpp