Refactor message parsing

Refactor some spaghetti code by splitting out subroutines into several
functions.

Signed-off-by: Lukas Fleischer <info@cryptocrack.de>