final submission with freeing pointers