refactoring sendmessage and keypress functions, should next turn these into directives