some cleanups, some c optimizations