Added comments in main.m and modified the code a little