[Refactoring] Fixed null reference exception.