Code refactor

Using C features that make the code more compact