Fixed null reference exceptions