Added null checking on accelerometer.