some cleanup, convert to c99 c