use err/warn from C library; lots of minor cleanup, lint