Fixed a silly fatal bug with freeing memory