Removed unused included header.
Using static keyword for local functions.
Using const keyword where necessary.
Merged fprintf calls where possible to reduce disk IO time.