Updated r code