Minimizing memory leak while improving ui speed