Fixed memory leaks and dpi loading