Finishing touches: added more comments and changed variable names for clarity