Fixed bad pointer and string usage; plugged some leaks and holes.