Fixed NPE and fixed warnings/errors