Bug fixed to avoid null reference.