extensively commented code

added a bunch of comments throughout the entire script, to make the
logic of the code more understandable