updated rdoc and made code simpler