There is not a single line of comments in any of this code ... please, please, please provide documentation, comments.  Its going to be very hard for anyone in the future to understand what you did.  And, when people don't understand what some block of code does, they usually end up re-inventing it or re-writing it ... which means that your code dies.  If you want  your work to live on long after you are done with it, you should add comments, documentation.