[Refactoring] Fixed possible null reference exception.