apply formatting and missing c headers

@dwins the patch looks good. I just applied the project's formatting rules and organized imports to get rid of unused ones, ad added missing c headers