Working out memory Leaks and bugs