move code logic inside the robot function