fixing bug in register_by_name function