added #indlude for stdio.h
Now checks if it has atleast 4 bytes of message to process
variable for write array now static to make sure it doesn't get discarded due to
context switching
Made a couple of variables in a function static to insure they stay