Broke up functions for readability and added comments.
Broke up functions for readability and added comments.