r code less horrible