added full logic for sending commands