public Message readMessages(String m1Command) throws IOException {
		Message msg = null;
		Iterator<Message> itr = messages.iterator();
		while (itr.hasNext()) {
			msg = itr.next();
			if (msg.getType().equals(m1Command) || m1Command == null) {
				itr.remove();
				return msg;
			}
		}

		String s;
		MessageFactory mf = MessageFactory.getInstance();
		while ((s = in.readLine()) != null) {
			if (MessageFactory.MSG_CLASSES.containsKey(s.substring(2, 4))) {
				msg = mf.getMessageClass(s);
			} else {
				msg = new Message(null, s);
			}

			if (msg.getType().equals(m1Command) || m1Command == null) {
				return msg;
			} else {
				this.messages.add(msg);
			}
		}

		return null;
	}