drop sprintf in favor of strdup where possible, clean-up code and fix typos.