Moved call to free to avoid mem leak