Fixed some leaks and deprecated code.