Fixed occasional null reference bug