Refactor core
Fix python3 compat bug in test_messages