improved high-level C code, updated docs