Fixed NPE and removed unused imports