Combining Potentiometer and Pushbutton Codes

Hello, I am currently working on a remote control system for a car. I have two Arduinos with two Xbees for wireless communication. I have one code that sends the state of a pushbutton serially, and another that receives it and turns the motor on. I have another code that reads the value of a potentiometer and sends it serially, and another that receives that value and sets the servo accordingly. I would like to combine these codes into one sending code and one receiving code. Below are my sending codes for the pushbutton-motor and the potentiometer-servo. Any help is much appreciated, thanks.

Motor Sending Code

int buttonPin = 2; //Value of button goes to pin 2
int val;

void setup()
{
Serial.begin(9600); //Begins serial communication
pinMode(buttonPin, INPUT); //Sets buttonPin as input
digitalWrite(buttonPin, HIGH);
}

void loop()
{
val = !digitalRead(buttonPin); //val set to state of buttonPin
Serial.write(val); //Send val serially
delay(100);
}

Servo Sending Code

int potpin = 0;
int val;

void setup ()
{
Serial.begin(9600); //Begin serial communication
}

void loop()
{
val = analogRead(potpin); //Read potentiometer pin call it val
Serial.write(val/4); //Divide val by 4 and send serially
delay(100);
}

Motor Receiving Code

int buttonPin = 2;
int val;

void setup()
{
Serial.begin(9600); //Begin serial communication
pinMode(10, OUTPUT); //Sets pin 10 as output
}

void loop()
{
if(Serial.available()) { //if the value coming in is >0
val = Serial.read(); //Read value coming in serially
digitalWrite(10, val); //Set motor to val
}
}

Servo Receiving Code

#include <Servo.h>
Servo myservo;

int val;

void setup()
{
Serial.begin(9600); //Begin serial communication
myservo.attach(9); //Attach servo to pin 9
}

void loop()
{
if (Serial.available() > 0) { //If value from potentiometer is >0
val = Serial.read(); //Read value coming in serially
val = map(val, 0, 255, 0, 179); //Map value for appropriate servo position
analogWrite(9, val); //Set servo pin to that value
myservo.write(val);
}
delay(15);
}

Thanks again!

//
// changed the pin to defines just to learn you something
//
#define POTPIN 0
#define BUTTONPIN 2

int potValue = 0;   // descriptive names; allways initialize is good practice
int buttonValue = 0;

void setup()
{
  Serial.begin(9600);

  pinMode(BUTTONPIN , INPUT);  //Sets buttonPin as input
  digitalWrite(BUTTONPIN , HIGH);
}

void loop()
{
  // DO MEASUREMENTS
  buttonValue = !digitalRead(BUTTONPIN ); 
  potValue = analogRead(POTPIN);  

  // PROCESS THEM
  potValue = potValue / 4;  

  // DISPLAY RESULTS
  Serial.print("Button: ");
  Serial.println(buttonValue );    //Send val serially  with a return 
  Serial.print("Potmeter: ");
  Serial.println(potValue );    //Send val serially  with a return 
  delay(100);
}

Think you can do the other two. Keep in mind to use descriptive variable names!
And there will be a problem as both the other sketches read from Serial. The way to solve that is to first send a byte that indicates what will follow, SERVO or MOTOR command (S or M)