Localizing more global functions, slight reorganization