refactored procmsg out to main