Start at the beginning and describe the general problem you're trying to solve / what you're trying to achieve - because if this isn't a learning exercise there's probably already something that does what you want (and it'll be better than that code), but if it is a learning exercise, I'm not just going to hand you a block of code that doesn't help you understand.