Updated code and comments

Added appropriate comments, and updated names of variables for clarity