Bugfix ClassCastException, check type before cast in sendMessage