slightly modified main.c