Refactoring of main.c