General cleanup CL. Added tons of comments, renamed some variables and functions.