Fixed bugs and NPE