Get rid of nested function

Nested functions is GCC extensions, avoid their use