That's quite a bit of code for someone to piece together and try to run/debug...you might receive a quicker response by breaking it down to the elements you are having a problem with (eg an SSCCE).