some fixes and created a function read_message