Fix compilation errors and reindent. Add #include directives