fixed check in incomingMessage function