Cleaning up code

Adding comments, refining formatting, and improving variable, function, and class names.