refactoring of MessageManager, implemented timeouts for lock