Add comments; some code cleanup