I know some of these might not be your code, but this should definitely be wrapped in an anonymous self-executing function to keep these variables local.