refactoring main.c