More $emessage -> $mes and code clean-up