Refactored motion sensors code