Completed main.c + small fixes