I can't get a clear idea about what is going on from line 324 to 372 just by looking the code. Can you please point me to the reference(s) you used in this section?