Adjusted tilt sensor and made code a little tidier