better logic for motion sensor