Reorganize library methods for readability and add comments to explain them