Fixed some syntax and logic errors.