Refactoring to avoid segfault at startup