WIP Porting utility functions to C (issue #131)

This is a work in progress