cleaned up implementation of C library functions