Pedantic cleanups
Resource leaks and printf format cleanups