Fixed inaccurate comment, memory leaks, and added error checking