reorganized code. added accelerometer