More refactoring, added message loop example