Add AnnotatedMessageHandler to replace the blocks of if statements and casts