Fixing possible null pointer exception