fixing npe and incorrect formatting