unfinished work with do_register
almost done version