Fixed sendMessage function