Added a lock for handling messages. This is one big lock.
Added the field typedata in connection.