Replies properly to PING messages.

Refactoring (dunno if it's better like this or not).