added free() calls that I forgot