Fixed a bug that generated null reference