Added prototype for sending generic messages; Added further error handling - errors are now propagated and connections closed