refactor main.c added misc.c