transliterating some C code to get feet wet