Fixed NPE and Cleanup