Added comments, did some re-naming for clarity.