Reply with NOT_UNDERSTOOD on unexpected message. Do some refactoring