added semaphore to receieved messages (messages cant be lost now)