Fixing leaks and adding example