Fixed an NPE + minor cleanup