Decomposed functions, partitioned them into new files, and added better commenting