fixed various NPEs and IOOBEs