Fixed null reference errors