Fixed leaks
Tidying up code.