Define 'its not working'... you've got a lot of code there that does several things so it can fail at any number of places. Break the problem down into its individual components and focus on what...