Commented, trimmed down to under 120 lines