reformatted the code in K&R style