Added comments on program logic