restructured c code for osx compat