handle messages loop fix