Minor spelling fix.
Reformatting. Mostly added braces to conditionals.
Also moved a sizeof() call outside of a for loop condition (performance).
Code formatting. Added braces to conditional statements.
Edited code formatting.