Looking at your `init` function, I would refactor it to not be so nested with if statements. Try logically inverting the if checks and returning early up near the top of the method and remove the else branches. Keep repeating this kind of refactoring on all your if statements. Eventually, you'll find that the "happy path" ends up at the bottom of the method and can return a success status without being so far indented. This style makes it easier to reason about what conditions are possible at various points in the method, i.e. you don't have to mentally compose the boolean logic conditions of all the nested if/else statements.<p>Here's an example I did: <a href="https://gist.github.com/JamesDunne/a94782bc39d95515f7dcc8516a18c5cb#file-init-refactor-c-L113" rel="nofollow">https://gist.github.com/JamesDunne/a94782bc39d95515f7dcc8516...</a><p>Also, I would generally move all implementation code out of header .h files into standard .c files. Header files are traditionally just meant to contain forward-declarations of types and methods.