Added logic to control a motor