ran through JSLint, fixed minor bugs