Added outgoing packet generation; code cleanup