Update main.c

few bug fixes