squash npe and improve