add comments, rename functions to be more readable.