serialize and encode; todo r,s as ints?