Fixed some leaks and deprecated code.
Merge remote-tracking branch 'origin'