cleaned up code: JSLint, set radix to 10 on parseInts, dealt with a few scoping issues