Explanatory comments + variable name changes

Added detailed comments to most lines to help understand and navigate
through the code. Also changed the names of some variables for
understanding and to emphasize the different roles those variables play
in the two main functions