Added program logic and comments.