Fixed a bug, not freeing allocated memory after usage