Made some functions inline.
Added #define guards.
Made indentation consistent.
Other minor changes.