fix bug and improve r() method