Fixed possible null pointer exception